package logic

import (
	"context"
	"fmt"
	"github.com/gogf/gf/util/guid"
	"github.com/tal-tech/go-zero/core/logx"
	"shape-erver/internal/svc"
	"shape-erver/internal/types"
	"shape-erver/task_process"
	"shape-erver/utils"
)

type AddTaskLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) AddTaskLogic {
	return AddTaskLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddTaskLogic) AddTask(req types.AddTaskReq) (*types.AddTaskResp, error) {

	taskGuid := guid.S()

	utils.SetTaskGuidToRedis(taskGuid, utils.QUEUED)
	err := task_process.AddShapeEToGIF(taskGuid, req.Prompt)
	if err != nil {
		fmt.Println("AddShapeEToGIF err:", err)
	}
	fmt.Println("taskGuid:", taskGuid)

	return &types.AddTaskResp{TaskId: taskGuid, Status: "ok"}, nil
}
